const models = require('../db/mysqldb/index')
const { Op } = require('sequelize')

class SysUser {
  /**
   * @description 获取用户信息
   * @param {string} user_id
   * @returns
   */
  static async findOne (user_id) {
    return await models.sys_user.findOne({
      where: {
        user_id,
        delete_timestamp: {
          [Op.is]: null
        }
      }
    })
  }

  /**
   * @description 获取用户信息
   * @param {string} user_id
   * @returns
   */
  static async findUser (user_id, realname) {
    const sql = `select su.user_id,su.realname,su.username,su.phone,su.avatar,su.sex FROM sys_user su WHERE su.user_id != ${user_id} and ( su.realname like '%${realname}%' or su.username like '%${realname}%' AND su.delete_timestamp is NULL)`
    const result = await models.sequelize.query(sql, {
      replacements: ['active'],
      type: models.sequelize.QueryTypes.SELECT,
    })
    return result
  }

}

module.exports = {
  SysUser
}
